<template>
  <div ref="myChart" class="trend-echarts" style="width: 100%; height: 100%"></div>
</template>

<script>
import * as echarts from "echarts"
export default {
  name: "echarts",
  components: {},
  data() {
    return {};
  },
  mounted() {
  },
  methods: {
    initChart(item) {
      console.log(item, 'item');
      let myChart = echarts.getInstanceByDom(this.$refs.myChart)

      if (myChart == null) {
        myChart = echarts.init(this.$refs.myChart)
      }
      const option = item.options
      myChart.setOption(option)

      // 监听窗口变化，响应图表
      window.addEventListener("resize", function () {
        if (myChart) {
          myChart.resize()
        }
      })
    }
  },
};
</script>

<style lang="scss" scoped></style>
